home *** CD-ROM | disk | FTP | other *** search
- /* kbhit.c --- p 520 */
- #include <stdio.h>
- #include <alloc.h>
- #include <graphics.h>
- main()
- {
- char far *image; /* Storage for image */
- char buffer[80];
- int x=0, y=0, xmax, ymax, gerror;
- unsigned numbytes;
- int gdriver=DETECT, gmode;
- intgraph (&gdriver, &gmode, "c:\\turboc");
- if (gerror=graphresult()) !=grOK
- {
- /* Error setting mode */
- printf("Error: %s\n",grapherrormsg(gerror));
- exit(0);
- }
- xmax=getmaxx();
- ymax=getmaxy();
- /* Draw a small stick figure to save */
- setcolor(YELLOW);
- fillellipse(5,5,5,5);
- moveto(5,10);
- lineto(5,20);
- lineto(0,30);
- moveto(10,30);
- lineto(5,20);
- moveto(0,15);
- lineto(0,10);
- lineto(10,15);
- /* Determine storage needed for entire screen and
- * display result. */
- numbytes = imagesize(0,0,10,30);
- /* allocate buffer for image */
- if ((image = (char far *) malloc(numbytes)) == (char far *)NULL)
- {
- closegraph();
- printf("Not enough memory for image storage\n");
- exit(0);
- }
- getimage(x,y,10,30,image); /* Save the image */
- /* Now clear screen and draw saved image at several
- * screen locations. */
- clearviewport();
- outtextxy(10,10,"Demonstrating animation with putimage");
- outtextxy(10, ymax_50,"Hit any key to exit:");
- x = xmax/2;
- y = ymax/2;
- putimage(x,y,image,XOR_PUT);
- /* Using kbhit and putimage, perform animation
- * until user hits a key. */
- while( !kbhit() )
- {
- /* Erase at last position */
- putimage(x,y,image,XOR_PUT);
- y += 2;
- x += 2;
- if(x> xmax-50) x = 50;
- if(y> ymax-50) y = 50;
- /* Redraw at new position */
- putimage(x,y,image,XOR_PUT);
- }
- /* Restore original mode */
- closegraph();
- }